/****************************************************
Matthew Hajduk
Anton K
Brian Graham
Shane Regel
Mackenzie Jordan

CS290: Principals of Software Development
Final Project 
12/13/13
****************************************************/

package twitterdba;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.JCommander;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.lang.Class;

public class twitterDBA{
	    public static class JCommanderParms {//At the moment, none of the analyses we have chosen require any parameters to be passed to them. If more are added that do, then they will need to be added here.
        @Parameter(names = {"-analysisFunction"}, description = "Analysis Function to be called", required = true)
        private String analysisFunction;
        
        @Parameter(names = "-zipFile", description = "Filename of zip archive to build SQL DB from",arity=1)
        private String zipFile=null;

        @Parameter(names = "-dbFile", description = "Filename of SQL DB that is either created, or if preBuilt is true, accessed",arity=1)
        private String dbFile = "Tweets.db";

        @Parameter(names = "-updateTweets", description = "Flag whether or not to go to Twitter and pull new tweets from there",arity=1)
        private boolean updateTweets = false;

        @Parameter(names = {"-preBuilt"}, description = "Flag for whether building a new SQL DB from a zip Archive, or accessing previously built DB", arity=1)
        private boolean preBuilt= false;
        
        public String getAnalysisFunction() {
            return analysisFunction;
        }

        public String getZipFile() {
            return zipFile;
        }

        public String getDBFile() {
            return dbFile;
        }

        public boolean getPreBuilt(){
        	return preBuilt;
        }

        public boolean getUpdateTweets(){
            return updateTweets;
        }
    }
	public static void main(String[] args){

	JCommanderParms parms = new JCommanderParms();
        new JCommander(parms, args);
        String analysisFunction = parms.getAnalysisFunction();
        String zipFile = parms.getZipFile();
        String dbFile = parms.getDBFile();
        boolean preBuilt = parms.getPreBuilt();
        boolean updateTweets = parms.getUpdateTweets();
        if (!preBuilt&&zipFile==null){//If preBuilt is false, Zip file name MUST be provided
            System.out.println("If preBuilt is false, Zip file name MUST be provided");
            return;
        }
        String returnTweet; //Defined here because otherwise Java throws an error due to it being used in two cases,
		ArrayList<String> returnUser = new ArrayList<String>();
        twitterDBAworker workerClass = new twitterDBAworker(dbFile,zipFile,preBuilt,updateTweets);
        switch(analysisFunction){//This calls constructor class for twitterDBAworker class and calls method given by analysisFunction. If any 	new analysis functions are added, they need to be included here, as well as any parameters that need to be passed.
        	case ("whoRetweetedMost"):
	        	returnUser = workerClass.whoRetweetedMost();
	        	System.out.println("The person (or people) who you retweeted the most is: " + returnUser);
        		break;
        	case ("rateGrammar"):
	        	double rateGrammar = workerClass.rateGrammar();
	        	System.out.println("Your grammar rating is : " + rateGrammar);
        		break;
        	case ("retweetsToTweets"):
	        	double rtweet = workerClass.retweetsToTweets();
    			System.out.println("Your retweet to tweet ratio is is: " + rtweet + "%");
    			break;
        	case ("mostRepliedTo"):
	        	returnUser = workerClass.mostRepliedTo();
	        	System.out.println("The person you replied to the most is: " + returnUser);
        		break;
        	case ("dbRating"):
	        	double dbRating = workerClass.dbRating();
	        	System.out.println("Your DB rating is: " + dbRating);
        		break;
        	default:
        	System.out.println("Function name not recognized. Please choose from one of the following: " + Arrays.toString(twitterDBAworker.getSupportedFunctions()));
        	break;
        }

	}
}
